home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr27 / ct.zip / BT.HPP next >
C/C++ Source or Header  |  1995-05-29  |  4KB  |  194 lines

  1. //Header file
  2. // M\Cooper, 3425 Chestnut Ridge Rd., Grantsville, MD 21536-9801
  3. // Email: thegrendel@aol.com
  4.  
  5. /***************************************************************************/
  6.  
  7. extern "C" two_tone(),
  8.        blatt(),
  9.     beep1();
  10.  
  11. #define PLAY 1
  12. #define GAME_OVER 1
  13. #define QUIT 2    
  14. #define ESC 27
  15. #define CR 13
  16. #define SPACE 32
  17. #define MAXLEN 4
  18. #define BUFSIZE 12
  19. /*******************/
  20. #define BLK_TIME 50
  21. #define Y_TIMEPOS 275
  22. /*********************/
  23. #define BIGNUMSIZE 10
  24. #define NAME_POS 190
  25.  
  26. #define POS_OFFSET 476
  27. // *ones digit*
  28.  
  29. #define POS1_OFFSET 392
  30. // *tens digit*
  31.  
  32. #define COLORS 15
  33. #define PATTERNS 11
  34. #define RADIUS 50
  35. #define X_C 315
  36. #define Y_C 225
  37. #define MOVES_X 316
  38. #define MOVES_Y 440
  39. #define BKGRND_COLOR WHITE
  40.  
  41. typedef enum { FALSE, TRUE } BOOLEAN;
  42. enum FLAG { OFF, ON };
  43. enum Player { WHITE_, BLACK_ };
  44.  
  45. char *player[] = { "White", "Black" },
  46.      esc_msg[] =   "Press ESC to exit",
  47.      title_msg[] = "Count Up Timer";
  48.  
  49. void graphics_setup( int ),
  50.      exit__(),
  51.      erase();
  52.  
  53.  
  54.  
  55. class CountdownTimer
  56.    {
  57.    protected:
  58.       int hours,
  59.       minutes,
  60.       moves,
  61.       warning,
  62.       text_color;
  63.       char line_clear [ BUFSIZE ];
  64.       Player p;
  65.       FLAG running_flag,
  66.        visual_ticking_flag,
  67.        time_warning_flag;
  68.       time_t seconds,
  69.          total_seconds,
  70.          total_seconds_mem,
  71.          start_t,
  72.          end_t,
  73.          startn_t,
  74.          interval_t,
  75.          running_t;
  76.    
  77.    public:
  78.       CountdownTimer()
  79.       {
  80.        hours = 0; minutes = 3; moves = 0; seconds = 0L;
  81.        total_seconds = total_seconds_mem = (long)hours * 3600L + (long)minutes * 60L;
  82.       }
  83.       CountdownTimer( int hrs, int min, time_t sec, Player pl )
  84.       {
  85.       hours = hrs; minutes = min; seconds = sec; moves = 0;
  86.       total_seconds = (long)hours * 3600L + (long)minutes * 60L + seconds;
  87.       total_seconds_mem = total_seconds;
  88.       p = pl;
  89.       }
  90.       CountdownTimer( int min, time_t sec, Player pl )
  91.       { 
  92.       sec += (long)min * 60L;
  93.       total_seconds = total_seconds_mem = sec; 
  94.       hours = sec / 3600;
  95.       minutes = ( sec % 3600 ) / 60;
  96.       seconds = sec % 60;
  97.       moves = 0;
  98.       p = pl;
  99.       }
  100.       CountdownTimer( int hrs, int min, Player pl )
  101.      {
  102.      hours = hrs; minutes = min; seconds = 0L; moves = 0;
  103.      total_seconds = total_seconds_mem = (long)hours * 3600L + (long)minutes * 60L;
  104.      p = pl;
  105.      }
  106.       CountdownTimer( time_t sec, Player pl )
  107.       {
  108.       total_seconds = total_seconds_mem = sec;
  109.       convert( sec );
  110.       p = pl;
  111.       moves = 0;
  112.       }
  113.  
  114.       CountdownTimer( int min )
  115.      {
  116.      hours = min / 60;
  117.      minutes = min % 60;
  118.      seconds = 0L; moves = 0;
  119.      total_seconds = total_seconds_mem = (long)min * 60L;
  120.      }
  121.  
  122.       void convert( time_t sec )
  123.       { 
  124.       hours = sec / 3600;
  125.       sec %= 3600;
  126.       minutes = sec / 60;
  127.       seconds = sec % 60;
  128.       }
  129.  
  130.       void display_time()
  131.       {
  132.       char dbuff [ BUFSIZE ];
  133.  
  134.          sprintf( dbuff,  "%02d:%02d:%02ld", hours, minutes, seconds );
  135.  
  136.          erase_numbers();  // Wipe off old time.
  137.          
  138.          setcolor( text_color );
  139.          outtextxy( BLK_TIME, Y_TIMEPOS, dbuff );
  140.          sprintf( line_clear, dbuff );
  141.       }
  142.  
  143.       BOOLEAN timeout()
  144.      {
  145.      if( !hours )
  146.         if( !minutes )
  147.            if( !seconds )
  148.           {
  149.           two_tone();
  150.           return ( TRUE );
  151.           }
  152.      return ( FALSE );
  153.      }
  154.  
  155. void exit_()
  156.    char ch;
  157.  
  158.       setcolor( BKGRND_COLOR );
  159.       settextstyle( TRIPLEX_FONT, HORIZ_DIR, 1 );
  160.       outtextxy( NAME_POS, 100, "Press a key to stop timer" );
  161.       setcolor( CYAN );
  162.       outtextxy( NAME_POS, 100, "Press a key to reset timer" );
  163.       ch = getch();
  164.       if( ch == ESC )
  165.      exit__(); // Quit.
  166.  
  167.       setcolor( BKGRND_COLOR );
  168.       outtextxy( NAME_POS, 100, "Press a key to reset timer" );
  169.       setcolor( BLUE );
  170.       outtextxy( NAME_POS, 100, "Press a key to stop timer" );
  171.  
  172.       return;
  173. }
  174.  
  175.       void initialize_clock()
  176.       {
  177.       running_flag = OFF;  //Clock is running.
  178.       running_t = 0;
  179.       start_t = time( NULL );
  180.       }
  181.  
  182.       void clock_on(),
  183.        erase_numbers(),
  184.        display_moves(),
  185.        reset_timer(),
  186.        erase();
  187.  
  188.       friend void play();
  189.  
  190.     
  191.     }; //end class defn.
  192.  
  193.